package com.wuyi.controller;

import com.wuyi.pojo.User;
import com.zc.utils.CookieUtils;
import com.zc.utils.JSONResult;
import com.zc.utils.JsonUtils;
import netscape.javascript.JSObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Set;

/**
 * @author 曾川
 * @version 1.0.0
 * @ClassName Hello.java
 * @Description 测试
 * @createTime 2021年09月15日 10:56:00
 */
@RestController
public class HelloController {

    final static Logger logger = LoggerFactory.getLogger(HelloController.class);


    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/hello")
    public Object hello() {
        logger.info("-----------info----------");
        logger.debug("-----------debug----------");
        logger.warn("-----------warn----------");
        logger.error("-----------error----------");
        return "Hello world";
    }


    @GetMapping("/set")
    public Object redis(@RequestParam String key, @RequestParam String value) {
        Long aLong = redisTemplate.opsForSet().add(key, value);
        return aLong;
    }



    @GetMapping("/isMem")
    public Object isMem(@RequestParam String key, @RequestParam String value) {
        Boolean member = redisTemplate.opsForSet().isMember(key, value);

        return member;
    }


    @GetMapping("/removeValue")
    public Object removeValue(@RequestParam String key, @RequestParam String value) {
        Long remove = redisTemplate.opsForSet().remove(key, value);

        return remove;
    }


    @GetMapping("/getSet")
    public Object getSet(@RequestParam String key) {
        Set<String> members = redisTemplate.opsForSet().members(key);
        for (String member : members) {
            System.out.println(member);
        }
        return "true";
    }

}
